package simplefactory;

public abstract class Operation {
    protected double number_a = 0;
    protected double number_b = 0;

    public void setNumber_a(double number_a) {
        this.number_a = number_a;
    }

    public double getNumber_b() {
        return number_b;
    }

    public void setNumber_b(double number_b) {
        this.number_b = number_b;
    }

    public double getNumber_a() {
        return number_a;
    }

    public abstract double getResult() throws Exception;
}

class OpreationAdd extends Operation {

    public double getResult() {
        return number_a  + number_b;
    }
}

class OpreationSub extends Operation {

    public double getResult() {
        return number_a  - number_b;
    }
}

class OpreationMul extends Operation {

    public double getResult() {
        return number_a  * number_b;
    }
}

class OpreationDiv extends Operation {

    public double getResult() throws Exception{
        if (0 == number_b) {
            throw new Exception("除数不能为 0");
        }
        return number_a  / number_b;
    }
}